import os
import pickle
import pprint

data: dict
file_name = "data.pkl"


def user_data_init():
    global data
    data = dict()
    if not os.path.exists(file_name):
        data = dict()
    else:
        if os.path.getsize(file_name) > 0:
            with open(file_name, "rb") as in_file:
                data = pickle.load(in_file)
        else:
            data = dict()
    save()


def object_for_key(key: str):
    try:
        return data[key]
    except Exception as e:
        print(e)
        return None


def save_object(key: str, value):
    data[key] = value
    save()


def save():
    with open(file_name, "wb") as output:
        pickle.dump(data, output)


def print_data():
    pprint.pprint(data)


def clean():
    global data
    data = dict()
    save()
